<?php

Yii::import('application.models._base.BaseSalestrans');

class Salestrans extends BaseSalestrans
{
    public static function model($className = __CLASS__)
    {
        return parent::model($className);
    }

    public function beforeValidate()
    {
        $this->tdate = new CDbExpression('NOW()');
        $this->user_id = Yii::app()->user->getId();
        return parent::beforeValidate();
    }

    public static function list_beuty_service($tgl)
    {
        $comm = Yii::app()->db->createCommand("SELECT
            ns.salestrans_id,ns.doc_ref,nsd.salestrans_details,nsd.barang_id,nsd.qty,nbe.beauty_id
            FROM {{salestrans}} AS ns
            INNER JOIN {{salestrans_details}} AS nsd ON nsd.salestrans_id = ns.salestrans_id
            INNER JOIN {{barang}} AS nb ON nsd.barang_id = nb.barang_id
            LEFT OUTER JOIN {{beauty}} AS nbe ON nsd.beauty_id = nbe.beauty_id
            INNER JOIN {{grup}} AS ng ON nb.grup_id = ng.grup_id
            WHERE ng.kategori_id = 1 AND ns.total >= 0 AND DATE(ns.tgl) = :tgl
        ");
        return $comm->queryAll(true,array(':tgl'=>$tgl));
    }
}